﻿#pragma once

#include "MapObject.h"
#include "../../Shared/Enums.h"
#include "../../Shared/Data/ItemData.h"
#include "../../Shared/Packet.h"
#include "DelayedAction.h"
#include "PlayerObject.h"
#include "MonsterObject.h"
#include "../../Shared/Data/Stat.h"
#include <string>
#include <vector>
#include <cmath>
#include "exceptionhelper.h"
#include "../../stringhelper.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects
{
    class ItemObject final : public MapObject
    {
    private:
        int CurrentMapIndex = 0;
        Point *CurrentLocation;

    public:
        virtual ~ItemObject()
        {
            delete Item;
        }

        ObjectType getRace() const override;

        std::string getName() const override;
        void setName(const std::string &value) override;

        int getCurrentMapIndex() const override;
        void setCurrentMapIndex(int value) override;
        Point *getCurrentLocation() const override;
        void setCurrentLocation(Point *value) override;
        MirDirection getDirection() const override;
        void setDirection(MirDirection value) override;
        unsigned short getLevel() const override;
        void setLevel(unsigned short value) override;

        bool getBlocking() const override;

        unsigned int Gold = 0;
        UserItem *Item;


        int getHealth() const override;

        int getMaxHealth() const override;

        ItemObject(MapObject *dropper, UserItem *item, bool DeathDrop = false);
        ItemObject(MapObject *dropper, UserItem *item, Point *manualpoint);
        ItemObject(MapObject *dropper, unsigned int gold);
        ItemObject(MapObject *dropper, unsigned int gold, Point *manuallocation);

        void Process() override;

        void SetOperateTime() override;


        bool Drop(int distance);

        bool DragonDrop(int distance);


        Packet *GetInfo() override;



        void Process(DelayedAction *action) override;
        bool IsAttackTarget(PlayerObject *attacker) override;
        bool IsAttackTarget(MonsterObject *attacker) override;
        int Attacked(PlayerObject *attacker, int damage, DefenceType type = DefenceType::ACAgility, bool damageWeapon = true) override;
        int Attacked(MonsterObject *attacker, int damage, DefenceType type = DefenceType::ACAgility) override;
        int Struck(int damage, DefenceType type = DefenceType::ACAgility) override;

        void ApplyPoison(Poison *p, MapObject *Caster = nullptr, bool NoResist = false, bool ignoreDefence = true) override;

        Buff *AddBuff(BuffType type, MapObject *owner, int duration, Stats *stat, bool visible = false, bool infinite = false, bool stackable = false, bool refreshStats = true, std::vector<int> &values) override;

        bool IsFriendlyTarget(PlayerObject *ally) override;

        bool IsFriendlyTarget(MonsterObject *ally) override;

        void Die() override;

        void SendHealth(PlayerObject *player) override;

        int Pushed(MapObject *pusher, MirDirection dir, int distance) override;

        void ReceiveChat(const std::string &text, ChatType type) override;
    };
}
